package net.mcreator.makecustomitem.procedure;

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.common.MinecraftForge;

import net.minecraft.world.World;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.init.Blocks;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.Entity;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.properties.IProperty;

import net.mcreator.makecustomitem.block.BlockMakeCustomItemBlock;
import net.mcreator.makecustomitem.ElementsMakecustomitemMod;

import java.util.Map;

@ElementsMakecustomitemMod.ModElement.Tag
public class ProcedureQFQBlockSet extends ElementsMakecustomitemMod.ModElement {
	public ProcedureQFQBlockSet(ElementsMakecustomitemMod instance) {
		super(instance, 19);
	}

	public static void executeProcedure(Map<String, Object> dependencies) {
		if (dependencies.get("entity") == null) {
			System.err.println("Failed to load dependency entity for procedure QFQBlockSet!");
			return;
		}
		if (dependencies.get("x") == null) {
			System.err.println("Failed to load dependency x for procedure QFQBlockSet!");
			return;
		}
		if (dependencies.get("y") == null) {
			System.err.println("Failed to load dependency y for procedure QFQBlockSet!");
			return;
		}
		if (dependencies.get("z") == null) {
			System.err.println("Failed to load dependency z for procedure QFQBlockSet!");
			return;
		}
		if (dependencies.get("world") == null) {
			System.err.println("Failed to load dependency world for procedure QFQBlockSet!");
			return;
		}
		Entity entity = (Entity) dependencies.get("entity");
		int x = (int) dependencies.get("x");
		int y = (int) dependencies.get("y");
		int z = (int) dependencies.get("z");
		World world = (World) dependencies.get("world");
		if (((world.getBlockState(new BlockPos((int) x, (int) y, (int) z))).getBlock() == Blocks.REDSTONE_BLOCK.getDefaultState().getBlock())) {
			if ((((entity.getHorizontalFacing()) == EnumFacing.NORTH) && ((((world.getBlockState(new BlockPos((int) (x - 1), (int) (y + 1), (int) z)))
					.getBlock() == Blocks.IRON_BLOCK.getDefaultState().getBlock())
					&& ((world.getBlockState(new BlockPos((int) (x + 1), (int) (y + 1), (int) z))).getBlock() == Blocks.GOLD_BLOCK.getDefaultState()
							.getBlock()))
					&& (((world.getBlockState(new BlockPos((int) (x + 1), (int) (y - 1), (int) z))).getBlock() == Blocks.IRON_BLOCK.getDefaultState()
							.getBlock())
							&& ((world.getBlockState(new BlockPos((int) (x - 1), (int) (y - 1), (int) z))).getBlock() == Blocks.GOLD_BLOCK
									.getDefaultState().getBlock()))))) {
				world.destroyBlock(new BlockPos((int) (x - 1), (int) (y + 1), (int) z), false);
				world.destroyBlock(new BlockPos((int) (x + 1), (int) (y + 1), (int) z), false);
				world.destroyBlock(new BlockPos((int) (x - 1), (int) (y - 1), (int) z), false);
				world.destroyBlock(new BlockPos((int) (x + 1), (int) (y - 1), (int) z), false);
				world.destroyBlock(new BlockPos((int) x, (int) y, (int) z), false);
				world.setBlockState(new BlockPos((int) x, (int) (y - 1), (int) z), BlockMakeCustomItemBlock.block.getDefaultState(), 3);
				try {
					IBlockState _bs = world.getBlockState(new BlockPos((int) x, (int) (y - 1), (int) z));
					for (IProperty<?> prop : _bs.getProperties().keySet()) {
						if (prop.getName().equals("facing")) {
							world.setBlockState(new BlockPos((int) x, (int) (y - 1), (int) z),
									_bs.withProperty((PropertyDirection) prop, EnumFacing.NORTH), 3);
							break;
						}
					}
				} catch (Exception e) {
				}
			} else if ((((entity.getHorizontalFacing()) == EnumFacing.EAST)
					&& ((((world.getBlockState(new BlockPos((int) x, (int) (y + 1), (int) (z - 1)))).getBlock() == Blocks.IRON_BLOCK.getDefaultState()
							.getBlock())
							&& ((world.getBlockState(new BlockPos((int) x, (int) (y + 1), (int) (z + 1)))).getBlock() == Blocks.GOLD_BLOCK
									.getDefaultState().getBlock()))
							&& (((world.getBlockState(new BlockPos((int) x, (int) (y - 1), (int) (z + 1)))).getBlock() == Blocks.IRON_BLOCK
									.getDefaultState().getBlock())
									&& ((world.getBlockState(new BlockPos((int) x, (int) (y - 1), (int) (z - 1)))).getBlock() == Blocks.GOLD_BLOCK
											.getDefaultState().getBlock()))))) {
				world.destroyBlock(new BlockPos((int) x, (int) (y + 1), (int) (z - 1)), false);
				world.destroyBlock(new BlockPos((int) x, (int) (y + 1), (int) (z + 1)), false);
				world.destroyBlock(new BlockPos((int) x, (int) (y - 1), (int) (z + 1)), false);
				world.destroyBlock(new BlockPos((int) x, (int) (y - 1), (int) (z - 1)), false);
				world.destroyBlock(new BlockPos((int) x, (int) y, (int) z), false);
				world.setBlockState(new BlockPos((int) x, (int) (y - 1), (int) z), BlockMakeCustomItemBlock.block.getDefaultState(), 3);
				try {
					IBlockState _bs = world.getBlockState(new BlockPos((int) x, (int) (y - 1), (int) z));
					for (IProperty<?> prop : _bs.getProperties().keySet()) {
						if (prop.getName().equals("facing")) {
							world.setBlockState(new BlockPos((int) x, (int) (y - 1), (int) z),
									_bs.withProperty((PropertyDirection) prop, EnumFacing.EAST), 3);
							break;
						}
					}
				} catch (Exception e) {
				}
			} else if ((((entity.getHorizontalFacing()) == EnumFacing.WEST)
					&& ((((world.getBlockState(new BlockPos((int) x, (int) (y + 1), (int) (z + 1)))).getBlock() == Blocks.IRON_BLOCK.getDefaultState()
							.getBlock())
							&& ((world.getBlockState(new BlockPos((int) x, (int) (y + 1), (int) (z - 1)))).getBlock() == Blocks.GOLD_BLOCK
									.getDefaultState().getBlock()))
							&& (((world.getBlockState(new BlockPos((int) x, (int) (y - 1), (int) (z - 1)))).getBlock() == Blocks.IRON_BLOCK
									.getDefaultState().getBlock())
									&& ((world.getBlockState(new BlockPos((int) x, (int) (y - 1), (int) (z + 1)))).getBlock() == Blocks.GOLD_BLOCK
											.getDefaultState().getBlock()))))) {
				world.destroyBlock(new BlockPos((int) (x - 1), (int) (y + 1), (int) z), false);
				world.destroyBlock(new BlockPos((int) (x + 1), (int) (y + 1), (int) z), false);
				world.destroyBlock(new BlockPos((int) (x - 1), (int) (y - 1), (int) z), false);
				world.destroyBlock(new BlockPos((int) (x + 1), (int) (y - 1), (int) z), false);
				world.destroyBlock(new BlockPos((int) x, (int) y, (int) z), false);
				world.setBlockState(new BlockPos((int) x, (int) (y - 1), (int) z), BlockMakeCustomItemBlock.block.getDefaultState(), 3);
				try {
					IBlockState _bs = world.getBlockState(new BlockPos((int) x, (int) (y - 1), (int) z));
					for (IProperty<?> prop : _bs.getProperties().keySet()) {
						if (prop.getName().equals("facing")) {
							world.setBlockState(new BlockPos((int) x, (int) (y - 1), (int) z),
									_bs.withProperty((PropertyDirection) prop, EnumFacing.WEST), 3);
							break;
						}
					}
				} catch (Exception e) {
				}
			} else if ((((entity.getHorizontalFacing()) == EnumFacing.SOUTH)
					&& ((((world.getBlockState(new BlockPos((int) (x + 1), (int) (y + 1), (int) z))).getBlock() == Blocks.IRON_BLOCK.getDefaultState()
							.getBlock())
							&& ((world.getBlockState(new BlockPos((int) (x - 1), (int) (y + 1), (int) z))).getBlock() == Blocks.GOLD_BLOCK
									.getDefaultState().getBlock()))
							&& (((world.getBlockState(new BlockPos((int) (x - 1), (int) (y - 1), (int) z))).getBlock() == Blocks.IRON_BLOCK
									.getDefaultState().getBlock())
									&& ((world.getBlockState(new BlockPos((int) (x + 1), (int) (y - 1), (int) z))).getBlock() == Blocks.GOLD_BLOCK
											.getDefaultState().getBlock()))))) {
				world.destroyBlock(new BlockPos((int) x, (int) (y + 1), (int) (z - 1)), false);
				world.destroyBlock(new BlockPos((int) x, (int) (y + 1), (int) (z + 1)), false);
				world.destroyBlock(new BlockPos((int) x, (int) (y - 1), (int) (z + 1)), false);
				world.destroyBlock(new BlockPos((int) x, (int) (y - 1), (int) (z - 1)), false);
				world.destroyBlock(new BlockPos((int) x, (int) y, (int) z), false);
				world.setBlockState(new BlockPos((int) x, (int) (y - 1), (int) z), BlockMakeCustomItemBlock.block.getDefaultState(), 3);
				try {
					IBlockState _bs = world.getBlockState(new BlockPos((int) x, (int) (y - 1), (int) z));
					for (IProperty<?> prop : _bs.getProperties().keySet()) {
						if (prop.getName().equals("facing")) {
							world.setBlockState(new BlockPos((int) x, (int) (y - 1), (int) z),
									_bs.withProperty((PropertyDirection) prop, EnumFacing.SOUTH), 3);
							break;
						}
					}
				} catch (Exception e) {
				}
			}
		}
	}

	@SubscribeEvent
	public void onRightClickBlock(PlayerInteractEvent.RightClickBlock event) {
		EntityPlayer entity = event.getEntityPlayer();
		int i = event.getPos().getX();
		int j = event.getPos().getY();
		int k = event.getPos().getZ();
		World world = event.getWorld();
		java.util.HashMap<String, Object> dependencies = new java.util.HashMap<>();
		dependencies.put("x", i);
		dependencies.put("y", j);
		dependencies.put("z", k);
		dependencies.put("world", world);
		dependencies.put("entity", entity);
		dependencies.put("event", event);
		this.executeProcedure(dependencies);
	}

	@Override
	public void preInit(FMLPreInitializationEvent event) {
		MinecraftForge.EVENT_BUS.register(this);
	}
}
